const { logsModel } = require('./models/logsModel.js')

//创建
module.exports.createLogs = async function ({name,operation,result}) {
    return await logsModel.create({name,operation,result})
}

//获取和搜索
module.exports.toObtainLogs = async function ({ time, pageSize, currentPage }) {
    if (time == null) {
        time=''
        const total = await logsModel.countDocuments()
        const pages = Math.ceil(total / pageSize)
        const get = await logsModel.find({ time: { $regex: time + '', $options: '$i' } }).limit(pageSize - 0).skip((currentPage - 1) * pageSize)
        return {
            total, pages, get
        }
    } else {
        const total = await logsModel.countDocuments({ time: { $regex: time + '', $options: '$i' } })
        const pages = Math.ceil(total / pageSize)
        const get = await logsModel.find({ time: { $regex: time + '', $options: '$i' } }).limit(pageSize - 0).skip((currentPage - 1) * pageSize)
        return {
            total, pages, get
        }
    }
}